@echo off

chcp 65001 > nul

REM 应用程序进程名称 (TODO:需要替换实际应用程序名)
set processName=SunloginClient.exe
REM 应用程序启动程序路径 (TODO:需要替换实际路径)
set applicationPath=F:\SunloginClient_10.2.1\SunloginClient\SunloginClient.exe
REM 延迟检查时间,单位:秒 (TODO:根据实际需要设置等待重试时间)
set checkInterval=300
REM 日志文件
set logFile=%cd%\xrkRun_log.txt
REM 启动成功累加器
set /a count=1
REM 启动失败累加器
set /a countFail=1

echo [%date% %time%] 检查%processName%应用程序启动情况开始 >> %logFile%

:loop
timeout /t %checkInterval% /nobreak > NUL

tasklist /fi "imagename eq %processName%" 2>NUL | find /i /n "%processName%">NUL
if "%ERRORLEVEL%"=="0" (
    echo [%date% %time%] 应用程序正在运行 >> %logFile%
    set /a count+=1
    if %count%==3 (
        echo [%date% %time%] 应用程序已启动成功，退出脚本 >> %logFile%
        exit
    )
) else (
    echo [%date% %time%] 应用程序没有运行 >> %logFile%
    powershell -Command "Start-Process -FilePath '%applicationPath%' -Verb RunAs"
    echo [%date% %time%] 应用程序自动拉起 >> %logFile%
    set /a countFail+=1
    if %countFail%==10 (
        echo [%date% %time%] 警告:应用程序启动失败，退出脚本 >> %logFile%
        exit
    )
)

goto loop
REM 发送post请求
curl -X POST http://example.com/api/data -H "Content-Type: application/json" -d "{\"key1\":\"value1\",\"key2\":\"value2\"}"